﻿using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace demo
{
    public class 钢筋
    {
        private ExternalCommandData _commandData;

        protected readonly Document document;

        public 钢筋(ExternalCommandData commandData)
        {
            _commandData = commandData;
            document = _commandData.Application.ActiveUIDocument.Document;
        }

        public void Test()
        {


           

            //test();


        }


        public void test()
        {
            DirectShapeLibrary shapeLibrary = DirectShapeLibrary.GetDirectShapeLibrary(document);
            CurveLoop loop = Profile.CreateCircle(10).CurveLoop;
            Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(new List<CurveLoop>() { loop }, XYZ.BasisZ, 10);
            shapeLibrary.AddDefinition("Rebar-Main", solid);

            CurveLoop loop2 = Profile.CreateCircle(5).CurveLoop;
            loop2.Transform(Transform.CreateTranslation(new XYZ(10, 10, 10)));
            Solid solid2 = GeometryCreationUtilities.CreateExtrusionGeometry(new List<CurveLoop>() { loop2 }, XYZ.BasisZ, 5);

            Category category = Category.GetCategory(document, BuiltInCategory.OST_Roads);

            using (Transaction transaction = new Transaction(document, "tCreateAndStore"))
            {
                transaction.Start();
                DirectShapeType shapeType = DirectShapeType.Create(document, "钢筋", category.Id);
                DirectShape.CreateElementInstance(document, shapeType.Id, category.Id, "Rebar-Main", Transform.CreateTranslation(new XYZ(-10, -10, -10)));
                DirectShape.CreateElementInstance(document, shapeType.Id, category.Id, "Rebar-Main", Transform.CreateTranslation(new XYZ(0, 0, 0)));
                DirectShape.CreateElementInstance(document, shapeType.Id, category.Id, "Rebar-Main", Transform.CreateTranslation(new XYZ(10, 10, 10)));

                // var shape = DirectShape.CreateElement(document, category.Id);
                //shape .SetShape(DirectShape.CreateGeometryInstance(document, "Rebar-Main", Transform.CreateTranslation(new XYZ(10, 10, 10))));
                //shape.SetTypeId(shapeType.Id);
                //shape.SetShape(new List<GeometryObject>() { solid });
                //shape.AppendShape(new List<GeometryObject>() { solid2 });
                transaction.Commit();
            }


        }

    }
}
